package com.cdxy.model.dto.base.exception;

import com.cdxy.model.dto.base.exception.enums.CommonErrorEnum;
import com.cdxy.model.dto.base.exception.enums.IError;
import com.cdxy.model.dto.base.exception.enums.SpecialErrorEnum;

import java.io.Serializable;

/**
 * @Author: tangy
 * @Date: 2020/2/23 17:27
 */
public class GdaException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = -871018851896931L;
    private int baseCode;
    private String baseMsg;
    private int layer;
    private int errorCode;

    public GdaException() {
        this(CommonErrorEnum.SYSTEM_ERROR.getDesc());
    }

    public GdaException(String message) {
        this((String) message, (Throwable) null);
    }

    public GdaException(Throwable throwable) {
        this(CommonErrorEnum.SYSTEM_ERROR.getDesc(), throwable);
    }

    public GdaException(String message, Throwable throwable) {
        super(message, throwable);
        this.baseCode = 0;
        this.baseMsg = "";
        this.layer = 0;
        this.errorCode = 0;
        this.setBaseCode(CommonErrorEnum.SYSTEM_ERROR.getCode());
        this.setBaseMsg(CommonErrorEnum.SYSTEM_ERROR.getDesc());
        this.setLayer(CommonErrorEnum.SYSTEM_ERROR.getLayerNum());
    }

    public GdaException(SpecialErrorEnum specialError) {
        this(specialError, specialError.getDesc());
    }

    public GdaException(SpecialErrorEnum specialError, String message) {
        this((SpecialErrorEnum) specialError, message, (Throwable) null);
    }

    public GdaException(SpecialErrorEnum specialError, Throwable throwable) {
        this(specialError, specialError.getDesc(), throwable);
    }

    public GdaException(SpecialErrorEnum specialError, String message, Throwable throwable) {
        super(message, throwable);
        this.baseCode = 0;
        this.baseMsg = "";
        this.layer = 0;
        this.errorCode = 0;
        this.setBaseCode(specialError.getCode());
        this.setLayer(specialError.getLayerNum());
        this.setBaseMsg(specialError.getDesc());
        this.setErrorCode(specialError.getCode());
    }

    public GdaException(IError iError) {
        this(iError, iError.getDesc());
    }

    public GdaException(IError iError, String message) {
        this((IError) iError, message, (Throwable) null);
    }

    public GdaException(IError iError, Throwable throwable) {
        this(iError, iError.getDesc(), throwable);
    }

    public GdaException(IError iError, String message, Throwable throwable) {
        super(message, throwable);
        this.baseCode = 0;
        this.baseMsg = "";
        this.layer = 0;
        this.errorCode = 0;
        this.setBaseCode(iError.getCode());
        this.setBaseMsg(iError.getDesc());
        this.setLayer(iError.getLayerNum());
    }

    public int getBaseCode() {
        return this.baseCode;
    }

    public void setBaseCode(int baseCode) {
        this.baseCode = baseCode;
    }

    public String getBaseMsg() {
        return this.baseMsg;
    }

    public void setBaseMsg(String baseMsg) {
        this.baseMsg = baseMsg;
    }

    public int getLayer() {
        return this.layer;
    }

    public void setLayer(int layer) {
        this.layer = layer;
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }
}
